home *** CD-ROM | disk | FTP | other *** search
- Path: newshub.ccs.yorku.ca!oz
- From: oz@nexus.yorku.ca (ozan s. yigit)
- Newsgroups: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
- Subject: Re: Readable Perl (was: Re: Relative Speed of Perl vs. Tcl vs. C)
- Date: 22 Feb 96 23:58:18
- Organization: The Electric Skillet
- Message-ID: <OZ.96Feb22235818@nexus.yorku.ca>
- NNTP-Posting-Host: nexus.yorku.ca
-
- some people seem to dislike tiny code examples, which seems rather
- strange: in capable hands, they speak volumes. it is true that not
- every posting includes such a gem, but i think there is room for even
- the good old fib. on the essay side, very few languages come with the
- type of tour-de-force tutorial [1] sather people have been able
- to put together, not sure why...
-
- anyway, just for the kicks, here is one fib due to kent dbybig. enjoy.
-
- ;;; fib with peano arithmetic (using numbers) with call/cc
-
- (define addc
- (rec addc
- (lambda (x y k)
- (if (zero? y)
- (k x)
- (addc (1+ x) (1- y) k)))))
-
- (define fibc
- (rec fibc
- (lambda (x c)
- (if (zero? x)
- (c 0)
- (if (zero? (1- x))
- (c 1)
- (addc (call/cc (lambda (c) (fibc (1- x) c)))
- (call/cc (lambda (c) (fibc (1- (1- x)) c)))
- c))))))
-
-
- oz
- ---
- [1] Michael Philippsen
- Sather 1.0 Tutorial
- International Computer Science Institute TR-94-062
- December 1994
-